<template>
  <div class="login">
    <div class="con center">
      <h3>登录</h3>
      <div class="line">
        <el-input placeholder="请输入账号" clearable v-model="user.username"></el-input>
      </div>
      <div class="line">
        <el-input placeholder="请输入密码" v-model="user.password" clearable show-password></el-input>
      </div>
      <div class="line">
        <el-button type="primary" @click="login">登录</el-button>
      </div>
    </div>
  </div>
</template>

<script>
import { mapGetters, mapActions } from "vuex";
import { requserlogin } from "../../request/api";
import { successAlert } from "../../utils/alert";
export default {
  mounted() {},
  computed: {},
  methods: {
    ...mapActions({
      changeUser: "reqlogin",
    }),
    login() {
      requserlogin(this.user).then((res) => {
        if (res.data.code === 200) {
          this.changeUser(res.data.list);
          console.log(res.data.list);
          successAlert(res.data.msg);

          this.$router.push("/index/home");
        }
      });
    },
  },
  data() {
    return {
      user: {
        username: "",
        password: "",
      },
    };
  },
};
</script>

<style lang='less' scoped>
@import "../../less/index.less";
.login {
  width: 100vw;
  height: 100vh;
  background: linear-gradient(to right, @parmary, @info);
}
.con {
  width: 300px;
  padding: @padding;
  border-radius: @margin;
  position: absolute;
  color: #fff;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
}
.center {
  text-align: center;
}
.line {
  margin-bottom: @margin;
}
</style>